package jmetal.metaheuristics.dnsgaii;

import java.util.HashMap;

import jmetal.core.Algorithm;
import jmetal.core.Operator;
import jmetal.core.Problem;
import jmetal.core.SolutionSet;
import jmetal.metaheuristics.nsgaII.NSGAII;
import jmetal.operators.crossover.CrossoverFactory;
import jmetal.operators.mutation.MutationFactory;
import jmetal.operators.selection.SelectionFactory;
import jmetal.problems.MORAP;
import jmetal.util.JMException;

public class RapMain {
	
	private final static int MAX_GENETATION = 500;
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static void main(String[] args) throws JMException, ClassNotFoundException {
		Problem problem = new MORAP("input_data/problems/morap_20.txt", 
				20, 5, 300) ;
		Algorithm algorithm = new DNSGAII(problem) ;
		
		algorithm.setInputParameter("populationSize", 300);
		algorithm.setInputParameter("maxEvaluations", 300 * MAX_GENETATION);
		
		HashMap parameters = new HashMap() ;
		parameters.put("probability", 0.9) ;
		Operator crossover = CrossoverFactory.
				getCrossoverOperator("SinglePointCrossover", parameters);
		
		parameters = new HashMap() ;
		parameters.put("probability",1.0 / problem.getNumberOfVariables()) ;		
		Operator mutation = MutationFactory.getMutationOperator("BitFlipMutation", parameters) ;
		// Selection Operator
		parameters = null;
		Operator selection = SelectionFactory.getSelectionOperator("BinaryTournament2", parameters);
		
		// Add the operators to the algorithm
		algorithm.addOperator("crossover", crossover);
		algorithm.addOperator("mutation", mutation);
		algorithm.addOperator("selection", selection);

		// if it is WFG this will be true
		algorithm.setInputParameter("normalization", true);
		
		SolutionSet population = algorithm.execute();
		population.printObjectivesToFile("FUN.tsv");
	}
}
